package yxy.game.pm2.module.conquest;

import yxy.game.pm2.bean.PlayerBean;
import yxy.game.pm2.bean.area.AreaBean;
import yxy.game.pm2.bean.module.AreaModule;
import yxy.game.pm2.bean.module.rank.PlayerRankModule;

import java.util.Collection;

public class RankConquest extends PlayerRankModule {

	public RankConquest(AreaBean areaBean) {
		super(areaBean);
	}

	@Override
	public String rankName() {
		return PlayerRankModule.getAllRankNames().get(2);
	}

	@Override
	protected long valuePlastic(long value) {
		return value * 1000;
	}

	@Override
	protected long valueRestore(long score) {
		return score / 1000;
	}

	static public void reset() {
		redis().client().getKeys().deleteByPattern("AREA:*:RANK:CONQUEST");

		Collection<PlayerBean> all = PlayerBean.all();

		for (PlayerBean bean : all) {
			String pCode = bean.getCode();
			AreaBean areaBean = AreaModule.area(bean);
			ConquestModule conquestModule = ConquestModule.get(pCode);
			if (conquestModule.getMapId() > 1) {
				new RankConquest(areaBean).put(pCode, conquestModule.getMapId());
			}
		}
	}

	static public RankConquest getRank(String playerCode) {
		AreaBean areaBean = AreaModule.area(playerCode);
		return new RankConquest(areaBean);
	}

}
